<?php
namespace app\service;
use think\facade\Db;
use app\model\ReceiptModel;
use Exception;

class ReceiptService{  

    public function all(){
        $users = ReceiptModel::select();        
        return $users;
    } 

    public function list($params){        
        $data = ReceiptModel::alias('a')->field('a.*,b.bank_name as subject')
        ->join('bank b','a.subject_id=b.id','left')
        ->where(['type'=>$params['type'],'income_id'=>$params['income_id']])->order('id','desc')->select(); 
        return $data;
    }   


    public function save($params){    
         
        if(empty($params['id'])){           
            $data = ReceiptModel::create($params); 
        }else{           
            $data = ReceiptModel::update($params, ['id' => $params['id']]); 
        }        
        return $data;
    }

    public function delete($params){   
        $data = ReceiptModel::destroy($params['id']);         
        return $data;
    }
}